function getid(id) {
    return document.getElementById(id);
}
function creat(cr) {
    return document.createElement(cr);
}
function gettn (tn) {
    return document.getElementsByTagName(tn);
}

var names = getid("name");
var age = getid("age");
var bt = getid("bt");
var bs = getid("bs");
var ta = getid("ta");


var arr = [
    //  ["","","",""]
];
n=0;

bt.onclick = function () {
    arr[n] = ["","","",""];
    arr[n][0] = +n+1;
    arr[n][1] = names.value;
    arr[n][2] = age.value;
    arr[n][3] = "删除";
    ta.appendChild(adds(n));
    n++;   
}

function adds (n) {
    var _tr = creat("tr");
    for (var i=0;i<4;i++) {
        var _td = creat("td");
        _td.innerText = arr[n][i];
        if (i == 3) { 
            _td.className = "del";
            // _td.onclick = sq();
        }
        _tr.appendChild(_td);
    }
    test()
    return _tr;
}

// function ddds (n) {
    
// }



function test() {
    var _del = document.getElementsByClassName("del");
    for (var k = 0;k < _del.length;k++) {
        (function (k) {   
                _del[k].onclick = function () {
                     var _deltr = _del[k].parentNode;
                    _deltr.remove();
                    console.log(k);
                }
        }(k))
    }

}


// function sq() {
//     var _deltr = _del[k].parentNode;
//    _deltr.remove();
//    console.log(k);
// }